<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-calendar"></i> 订单管理
                </el-breadcrumb-item>
                <el-breadcrumb-item>用户竞猜</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-row>
                    <el-col :span="4">
                        <el-date-picker
                                v-model="query.start_time"
                                type="datetime"
                                placeholder="开始时间">
                        </el-date-picker>
                    </el-col>
                    <el-col :span="4">
                        <el-date-picker
                                v-model="query.end_time"
                                type="datetime"
                                placeholder="结束时间">
                        </el-date-picker>
                    </el-col>


                    <el-col :span="16" style="display:flex;justify-content: center;">

                        <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
                        <el-button type="primary" icon="el-icon-download" @click="exportSource">导出数据</el-button>
                    </el-col>
                </el-row>
            </div>
            <el-table
                    id="repottable"
                    :data="tableData"
                    border
                    v-loading="loading"
                    class="table"
                    ref="multipleTable"
                    header-cell-class-name="table-header"
                    @selection-change="handleSelectionChange"
            >
                <el-table-column type="selection" width="55" align="center"></el-table-column>
                <el-table-column prop="id" label="ID" sortable width="55" align="center"></el-table-column>
                <el-table-column prop="order_no" label="订单号"   align="center"></el-table-column>
                <el-table-column prop="total_price" label="竞猜数量"></el-table-column>
                <el-table-column prop="buyer_mobile" label="手机号"></el-table-column>
                <el-table-column prop="open_str" label="开奖结果"></el-table-column>
                <el-table-column prop="open_qh" label="竞猜期号" width="160px"></el-table-column>
                <el-table-column prop="d_txt" label="本次竞猜"></el-table-column>
                <el-table-column label="是否中奖" align="center" >
                    <template slot-scope="scope">
                        <p v-if="scope.row.status == 0 ">开奖中</p>
                        <p v-if="scope.row.status == 1 ">中奖</p>
                        <p v-if="scope.row.status == 2 ">未中奖</p>
                    </template>
                </el-table-column>
                <el-table-column label="本期开奖结果" align="center" >
                    <template slot-scope="scope">
                        <p v-if="scope.row.open_str == null ">还未更新</p>
                        <p v-else>{{scope.row.open_str}}</p>
                    </template>
                </el-table-column>
                <el-table-column prop="created_at" label="创建时间"></el-table-column>
                <el-table-column prop="updated_at" label="更新时间"></el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                        background
                        layout="total, prev, pager, next,sizes"
                        :page-sizes="[0,10, 20, 50,100 ,500,1000]"
                        @size-change="handleSizeChange"
                        :current-page="query.page"
                        :page-size="query.pageSize"
                        :total="pageTotal"
                        @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>
        <!-- 编辑发货 -->
        <el-dialog title="编辑中奖号码" v-dialogDrag :visible.sync="zjVisible" width="380px">
            <el-form ref="edit" :model="zj_model" label-width="90px">
                【{{zj_model.open_qh}}】期
            </el-form>
            <el-form ref="edit" :model="zj_model" label-width="90px">
                <el-form-item label="中奖号码" class="form-item">
                    <el-input
                            v-model="zj_model.open_code"
                            maxlength="30"
                            type="text"
                            minlength="2"
                            placeholder="请输入开奖号码"
                    ></el-input>
                </el-form-item>
                <el-form-item label="开奖时间" class="form-item">
                    <el-input
                            v-model="zj_model.open_time"
                            maxlength="30"
                            type="text"
                            minlength="2"
                            placeholder="请输入开奖时间"
                    ></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="zjVisible = false">取 消</el-button>
                <el-button type="primary" @click="update_zj">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>

    export default {
        name: 'report',
        data () {
            return {
                query: {
                    page: 1,
                    pageSize: 10,
                    status: '',
                    sort: '1'
                },
                deliverVisible: false,
                deliver: {},
                loading: false,
                tableData: [],
                multipleSelection: [],
                pageTotal: 0,
                delList: [],
                idx: -1,
                id: -1,
                zjVisible:false,
                zj_model: {},
                //获取列表请求
                getList: function () {
                    let that = this;
                    this.api.get('getGuess', this.query, res => {
                        for (let i in res.data.list) {
                            res.data.list[i].status = res.data.list[i].status + '';
                        }
                        that.tableData = res.data.list;
                        that.query.page = res.data.page;
                        that.query.pageSize = res.data.pageSize;
                        that.pageTotal = res.data.pageTotal;
                    }, undefined, undefined, this);
                },
                //删除请求
                delLists: function (ids, msg) {
                    let that = this;
                    if (ids.length < 1) {
                        this.$message.error('请选择删除的数据');
                        return false;
                    }
                    // 二次确认删除
                    this.$confirm('确定要删除吗？', '提示', {
                        type: 'warning'
                    }).then(() => {
                        that.api.delete('delReport', { ids: ids }, res => {
                            that.query.page = 1;
                            that.getList();
                            that.multipleSelection = [];
                            that.$message.success(res.msg);
                        }, undefined, undefined, this);
                    }).catch(() => { });
                }
            };
        },
        created () {
            this.getList();

        },
        methods: {
            // 触发搜索按钮
            handleSearch () {
                this.$set(this.query, 'page', 1);
                this.getList();
            },
            exportSource(){
                this.api.exportExcel(document.querySelector('#repottable'),'用户竞猜数据表')
            },
            handleSizeChange(val){
                console.log(val)
                if(val == 0){
                    this.query.pageSize = 100000000;
                }else{
                    this.query.pageSize = val;
                }
                this.getList();
            },

            /**
             * 添加编辑
             */
            handleEdit (index, row, status) {
                this.$confirm('确定要' + (status == 1 ? '通过' : '拒绝') + '审核吗？', '提示', {
                    type: 'warning'
                }).then(() => {
                    this.api.put('statusReport', { id: row.id, status: status }, res => {
                        this.tableData[index].status = status;
                        this.$message.success(res.msg);
                    });
                }).catch(() => { });
            },


            /**
             * 发货单号编辑事件
             */
            deliverEdit (index, row) {
                this.deliver = {
                    id: row.id,
                    deliver_desc: row.deliver_desc,
                    deliver_sn: row.deliver_sn
                };
                this.deliverVisible = true;
            },
            ZjEdit (row) {
                this.zj_model = {
                    id: row.id,
                    open_code: '',
                    open_qh: row.open_qh,
                    open_time: '',
                };
                this.zjVisible = true;
            },

            /**
             * 复制文本
             */
            copy (text) {
                if (!text || text == '' || text == ' ') {
                    this.$message.error('没有可复制的信息');
                    return false;
                }
                this.$copyText(text).then(() => {
                    this.$message.success('复制成功');
                }, () => {
                    this.$message.error('复制失败，当前浏览器不支持复制');
                });
            },

            /**
             * 保存发货信息
             */
            saveDeliver () {
                this.api.put('report-deliver', this.deliver, res => {
                    this.deliverVisible = false;
                    this.$message.success('保存成功');
                    this.getList();
                }, undefined, undefined, this);
            },

            showText (title, text) {
                this.$alert(text, title, {
                    confirmButtonText: '确定',
                    callback: action => {

                    }
                });
            },
            // 多选操作
            handleSelectionChange (val) {
                this.multipleSelection = val;
            },

            // 删除操作
            handleDelete (index, row) {
                this.delLists([row.id], '删除成功');
            },
            //批量删除
            delAllSelection () {
                const length = this.multipleSelection.length;
                let str = '';
                this.delList = this.delList.concat(this.multipleSelection);
                let ids = [];
                for (let i = 0; i < length; i++) {
                    str += this.multipleSelection[i].name + ' ';
                    ids.push(this.multipleSelection[i].id);
                }
                this.delLists(ids, `删除了${str}`);
            },
            // 分页导航
            handlePageChange (val) {
                this.$set(this.query, 'page', val);
                this.getList();
            },
            update_zj() {
                this.$confirm('你确定修改？', {
                    type: 'warning'
                }).then(() => {
                    this.handleOk()
                }).catch(() => { });
            },
            handleOk(){
                this.zjVisible = false;
                this.api.post('guess_update',{id: this.zj_model.id,open_code:this.zj_model.open_code,open_qh:this.zj_model.open_qh,open_time:this.zj_model.open_time}, res => {
                    this.zjVisible = false;
                    this.$message.success('保存成功');
                    this.getList();
                }, undefined, undefined, this);
            },
        }
    };
</script>

<style scoped>
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-select {
        width: 120px;
    }
    .show-text {
        cursor: pointer;
        color: #75c0ed;
    }
    .show-text:hover {
        color: #2e91cd;
    }
    .handle-input {
        width: 300px;
        display: inline-block;
    }
    .table {
        width: 100%;
        font-size: 14px;
    }
    .red {
        color: #ff0000;
    }
    .mr10 {
        margin-right: 10px;
    }
    .table-td-thumb {
        display: block;
        margin: auto;
        width: 40px;
        height: 40px;
    }
</style>
